<template>
    <el-tab-pane label="StatefulSet" name="statefulset">
        <el-row style="float: right">
            <el-input style="width: 200px" v-model="pod_table_search" size="small" placeholder="搜索" />
        </el-row>
        <el-table :height="tableH" size="mini" :data="filter_pod_table_search_data" :cell-style="{ padding: 0 }"
            tooltip-effect="dark" style="font-size: 10px; width: 100%" @selection-change="selection_pod_table">
            <el-table-column type="selection" width="55"> </el-table-column>
            <el-table-column show-overflow-tooltip label="服务名称" prop="name" width="400">
            </el-table-column>
            <el-table-column prop="pod_ip" label="服务IP" width="120">
            </el-table-column>
            <el-table-column prop="namespace" label="空间" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="ports" label="服务端口" show-overflow-tooltip>
            </el-table-column>
            <el-table-column prop="node_ports" label="外部端口" show-overflow-tooltip>
            </el-table-column>
        </el-table>
    </el-tab-pane>
</template>

<script lang="ts" setup>
import { computed, ref } from 'vue';
import * as Request from "@/general/request";
import { ElMessage } from 'element-plus';

const pod_table_search = ref("");
let server_pod_form = ref([]);
const tableH = document.documentElement.clientHeight - 320

const filter_pod_table_search_data = computed(() =>
      server_pod_form.value.filter((data) => {
        const values: Array<any>  = Object.values(data);
        for (var i in values) {
          if (values[i]) {
            if (values[i].includes(pod_table_search.value.toLowerCase())) {
              return true;
            }
          }
        }
      })
    );

    const get_k8s_cluster_pod = async (kubernetes_cluster_id: string) => {
      const response = await Request.GET("/background/home/kubernetes/pod", {
        kubernetes_cluster_id: kubernetes_cluster_id,
      });
      if (response && response.data) {
        let return_data = response.data;
        if (return_data.success) {
          server_pod_form.value = return_data.data;
          ElMessage.success(return_data.msg);
        } else {
          ElMessage.error(return_data.msg);
        }
      }
    };

    
const selection_pod_table = (e: String) => {
      console.log(e);
    };

//  将方法暴露
defineExpose({
  get_k8s_cluster_pod
})

</script>